﻿using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Data;

namespace TestFontResize
{
    public partial class Window1
    {
        public static readonly DependencyProperty FontSizeIncrementProperty = DependencyProperty.Register("FontSizeIncrement", typeof (double), typeof (Window1),
            new PropertyMetadata(OnFontSizeIncrementChanged));

        private static void OnFontSizeIncrementChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            //double oldValue = Math.Abs((double) e.OldValue);
            //double newValue = Math.Abs((double) e.NewValue);
            double oldValue = (double) e.OldValue;
            double newValue = (double) e.NewValue;
            double delta = newValue - oldValue;

            o.SetValue(FontSize1Property, (double)o.GetValue(FontSize1Property) + delta);
            o.SetValue(FontSize2Property, (double)o.GetValue(FontSize2Property) + delta);

            //if (oldValue < newValue) //increasing
            //{
            //}
            //else
            //{
            //    if (oldValue > newValue) //decreasing
            //    {
            //        o.SetValue(FontSize1Property, (double) o.GetValue(FontSize1Property) - delta);
            //        o.SetValue(FontSize2Property, (double) o.GetValue(FontSize2Property) - delta);
            //    }
            //}


        }

        public double FontSizeIncrement
        {
            get {return (double) GetValue(FontSizeIncrementProperty);}
            set {SetValue(FontSizeIncrementProperty, value);}
        }

        public static DependencyProperty FontSize1Property = DependencyProperty.Register("FontSize1", typeof (double), typeof (Window1));
        public double FontSize1
        {
            get { return (double)GetValue(FontSize1Property); }
            set { SetValue(FontSize1Property, value); }
        }

        public static DependencyProperty FontSize2Property = DependencyProperty.Register("FontSize2", typeof(double), typeof(Window1));
        public double FontSize2
        {
            get { return (double)GetValue(FontSize2Property); }
            set { SetValue(FontSize2Property, value); }
        }

        public Window1()
        {
            InitializeComponent();

            //var binding = new Binding("Value") { Source = slider };
            //BindingOperations.SetBinding(Win1, FontSizeIncrementProperty, binding);



            FontSize1 = 10;
            FontSize2 = 20;
            FontSizeIncrement = 0;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            FontSizeIncrement = 10;
        }

        private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            FontSizeIncrement = e.NewValue;
        }
    }
}
